<?php

//  list.php
//  Memento 3.0
//
//  Created by Christopher Burrows on 10-08-01
//  Copyright 2010 Team Memento. All rights reserved.
//
//    Description:
//  Enumerates the memory ids of each memory attached to
//  a collection_id, which is retrieved from the passed
//  session_token.
//
//  10-08-01: File created. (C. Burrows)
//
//  HTML POST Fields:
//  'session_token' (string)
//
//  OUTPUT:
//  Line 1: False if validation fails
//  Line 2-n+1: Memory id of Memory n-1.

include ($_SERVER['DOCUMENT_ROOT'].'/functions.php');
connect_to_database();

$session_token = $_REQUEST ['session_token'];

if (!validate_session_token($session_token)) {

    echo '0'.PHP_EOL;

} else {
    
    echo '1'.PHP_EOL;

    // Get the collection_id
    $result = mysql_query("SELECT * FROM sessions WHERE
            session_token='$session_token'");
    $row = mysql_fetch_array($result);
    $collection_id = $row['collection_id'];
    
    // Get an array of memory_ids associated with that collection_id
    $result = mysql_query("SELECT * FROM memories WHERE
            collection_id='$collection_id'");
   
    while ($row = mysql_fetch_array($result))
        echo $row['memory_id'].PHP_EOL;
        
}

?>